package lrh.hubu.firstproject;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class privateFragment extends Fragment {

    private View view;
    private ArrayList<String> mylist = new ArrayList<>();
    private ArrayList<mydata> myDataList = new ArrayList<mydata>();
    RecyclerView rView;
    GridAdapter adapter;

    public privateFragment() {
        // Required empty public constructor
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.t4, container, false);


        initGridadapt();
        initdata();

        initData();



        return view;
    }
    private void initdata(){
        mylist.add("诺克萨斯之手,无可匹敌的力量!");
        mylist.add("潮汐海灵,浪潮逆转吧");
        mylist.add("发条魔灵,我们会为你杀敌，这肯定很有趣");
        mylist.add("瘟疫之源,来次下水道里的 末~日~");
        mylist.add("虚空恐惧,For the darkness");
        mylist.add("众星之子,众星，聆听我的祈求");
        mylist.add("暴走萝莉,规则，就是用来打破");
        mylist.add(",");
        mylist.add(",");
        mylist.add(",");
        mylist.add(",");
        mylist.add(",");
        mylist.add(",");
        mylist.add(",");
        mylist.add(",");
    }

    private void initData() {
        for (int i = 0; i < mylist.size(); i++) {
            mydata bean = new mydata();

            String s = mylist.get(i);
            // group
            String group = s.substring(0, s.indexOf(","));
            // name
            String team = s.substring(s.indexOf(",") + 1, s.length());

            bean.setGroup(group);
            bean.setName(team);

            myDataList.add(bean);
        }
    }

    public void initGridadapt(){
        rView = view.findViewById(R.id.recyclerview4);
         adapter = new GridAdapter(getActivity());

//        final TextView tvGroup = view.findViewById(R.id.t4_top1);

//        RecyclerView rcvGrid = findViewById(R.id.recyclerview1);

        GridLayoutManager managerGrid = new GridLayoutManager(getActivity(),2);
//        managerGrid.setOrientation(GridLayoutManager.VERTICAL);

//        LinearLayoutManager managerGrid = new LinearLayoutManager(getActivity());
//        managerGrid.setOrientation(LinearLayoutManager.VERTICAL);

        rView.setLayoutManager(managerGrid);
        rView.setHasFixedSize(true);
        rView.setAdapter(adapter);

        adapter.setList(myDataList);

//        rView.addOnScrollListener(new RecyclerView.OnScrollListener() {
//            @Override
//            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
//                super.onScrolled(recyclerView, dx, dy);
//
//                View stickyInfoView = recyclerView.findChildViewUnder(tvGroup.getMeasuredWidth() / 2, 5);
//
//                if (stickyInfoView != null && stickyInfoView.getContentDescription() != null) {
//                    tvGroup.setText(String.valueOf(stickyInfoView.getContentDescription()));
//                }
//
//                View transInfoView = recyclerView.findChildViewUnder(
//                        tvGroup.getMeasuredWidth() / 2, tvGroup.getMeasuredHeight() + 1);
//
//                if (transInfoView != null && transInfoView.getTag() != null) {
//
//                    int transViewStatus = (int) transInfoView.getTag();
//                    int dealtY = transInfoView.getTop() - tvGroup.getMeasuredHeight();
//
//                    if (transViewStatus == GridAdapter.HAS_STICKY_VIEW) {
//                        if (transInfoView.getTop() > 0) {
//                            tvGroup.setTranslationY(dealtY);
//                        } else {
//                            tvGroup.setTranslationY(0);
//                        }
//                    } else if (transViewStatus == GridAdapter.NONE_STICKY_VIEW) {
//                        tvGroup.setTranslationY(0);
//                    }
//                }
//            }
//        });
    }
}